import shutil
import os
import time 
#svn
SVNADD = 'svn add {0}'
SVNCOMMIT =  'svn commit -m "commitnewversion" --username=qiqian --password=123456'

SVNPath = '/Users/admin/client_app/updataSvn/res_update/'
UPSERVERPath = '/Users/admin/client_app/ansible_workspace/'
def getSVNADDCMD(zipname):
  return SVNADD.format(zipname)

if __name__ == "__main__":
    Branchname = os.environ['CustomerBranch']
    Producttype = os.environ['Producttype']
    updataSvnDir = "./updataSvn/"
    allBranchdir  = "./hotupdata_"+Branchname
    print("allBranchdir   copyfile  is ",allBranchdir)
    if os.path.exists("./hotupdata_install"):
        shutil.rmtree("./hotupdata_install")
    if os.path.exists("./hotupdatatemp"):
        shutil.copytree("./hotupdatatemp", "./hotupdata_install")
        if os.path.exists(allBranchdir):
            shutil.rmtree(allBranchdir)
        shutil.copytree("./hotupdatatemp", allBranchdir)
    if os.path.exists("./hotupdata"):
        shutil.rmtree("./hotupdata")
        zipname = time.strftime("%Y%m%d%H%M%S", time.localtime())+Branchname+"_"+Producttype
        shutil.copytree("./hotupdatatemp", "./hotupdata")
        shutil.rmtree("./hotupdatatemp")
        shutil.make_archive(SVNPath+zipname, "zip", "./hotupdata")
        # os.chdir(SVNPath)
        # svnaddcmd = getSVNADDCMD(zipname+".zip")
        # print("svnaddcmd  is ",svnaddcmd)
        # os.system(svnaddcmd)
        # os.system(SVNCOMMIT)
    if os.path.exists(UPSERVERPath+"hotupdata.zip"):
        os.remove(UPSERVERPath+"hotupdata.zip")
    zipname = "hotupdata"
    shutil.make_archive(UPSERVERPath+zipname, "zip", "/Users/admin/client_app/hotupdata")

        
        



